var SERVER_HOST = 'http://www.51dzzs.com';
// var SERVER_HOST = 'http://localhost:8080';

function toFormData (data) {
    let formData = new FormData();
    for (let key in data) {
        formData.append(key, data[key]);
    }
    return formData;
}

function trim (str) {
    return str.replace(/^\s+|\s+$/g, '');
}

function getAjax(){
    return axios.create({
        baseURL: SERVER_HOST,
        timeout: 30000
    })
}

function getDate(data,type) {
    let myDate;
    if (data instanceof Date){
        myDate = data;
    } else if (typeof(data) == 'number') {
        myDate = new Date(data);
    } else {
        return data;
    }
    let Y = myDate.getFullYear(),
        M = myDate.getMonth() + 1,
        D = myDate.getDate(),
        H = myDate.getHours(),
        Min = myDate.getMinutes(),
        S = myDate.getSeconds();
    if (M < 10) {
        M = '0' + M;
    }
    if (D < 10) {
        D = '0' + D;
    }
    if (H < 10) {
        H = '0' + H;
    }
    if (Min < 10) {
        Min = '0' + Min;
    }
    if (S < 10) {
        S = '0' + S;
    }
    if(type == 'date'){
        return Y + '-' + M + '-' + D ;
    }else{
        return Y + '-' + M + '-' + D +' '+ H + ':' +Min + ':' + S;
    }
}

function getUrlKey(name) {
    var paramReg = new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)');
    var value = null;
    if (paramReg.exec(location.href)) {
        value = decodeURIComponent((paramReg.exec(location.href) || [''])[1].replace(/\+/g,'%20')) || null
    }
    return value;
}